package cn.darksoul3.spark.dataset

import org.apache.spark.sql.{Dataset, SparkSession}

object WCWithDataSetByDSL {

  def main(args: Array[String]): Unit = {

    val ss: SparkSession = SparkSession.builder().appName("WCWithDataSet").master("local[*]").getOrCreate()
    val lines: Dataset[String] = ss.read.textFile("C:\\Users\\cary2\\Desktop\\wordcount.txt")
    import ss.implicits._
    val words: Dataset[String] = lines.flatMap(_.split("\\s+"))

    val res = words
      .groupBy(cols = $"value".as("word"))
      .count().withColumnRenamed("count","counter")
      .orderBy($"counter".desc)
    //words.printSchema()
    res.show()



    ss.stop()
  }

}
